﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Boomer.Source.TiledMap;
using Microsoft.Xna.Framework;

namespace Boomer.Source.Breakable_Object
{
    class ObjectManager
    {
        private static ObjectManager manager = null;

        private List<CBreakableObject> lisObject;

        private CTiledMap map;

        ObjectManager()
        {
            lisObject = new List<CBreakableObject>();
        }

        public static ObjectManager getInstance()
        {
            if (manager == null)
                manager = new ObjectManager();

            return manager;
        }

        public void addObject(CBreakableObject pObj)
        {
            lisObject.Add(pObj);
        }

        public void breaking(Vector2 mapIndex)
        {
            int count = lisObject.Count;

            for (int i = 0; i < count; ++i)
            {
                if (lisObject[i].mapPos == mapIndex)
                {
                    lisObject[i].breaking(true);
                }
            }
        }

        public void update(float deltaTime)
        {
            int count = lisObject.Count;

            for (int i = 0; i < count; ++i)
            {
                if( lisObject[i].m_isAlive)
                    lisObject[i].update(deltaTime);
            }
        }

        public void draw()
        {
            int count = lisObject.Count;

            for (int i = 0; i < count; ++i)
            {
                if (lisObject[i].m_isAlive)
                    lisObject[i].draw();
            }
        }

        public void clear()
        {
            lisObject.Clear();
        }
    }
}
